<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/4/13
 * Time: 16:10
 */

namespace app\storage\common;

use app\storage\model\SupplierModel;

class Template
{

    public static function bomTemplate($uuid, $orderId, $fentryid, $storageUuid, $supplierUuid, $operateType, $type, $hidden = 0, $productType = '', $workShop = '', $remark = '')
    {
        $supplierModel = new SupplierModel();
        if (!empty($supplierUuid)) {
            $supplierType = $supplierModel->where('uuid', $supplierUuid)->value('type');
            $tempType = $supplierType == AppConstant::SUPPLIER_B ? AppConstant::BOM_B : AppConstant::BOM_W;
        } else {
            //  $supplierType = AppConstant::SUPPLIER_B;
            $tempType = AppConstant::BOM_B;
        }
        $type = $type == '' ? $tempType : $type;
        $productType = $type == AppConstant::BOM_B ? '普通订单' : '委外订单';
        $workShop = empty($workShop) ? '生产部' : $workShop;
        $orderId = empty($orderId) ? create_unique_id('BOM') : $orderId;
        return [
            'uuid' => empty($uuid) ? create_uuid() : $uuid,
            'order_id' => $orderId,
            'fentryid' => empty($fentryid) ? '' : $fentryid,
            'product_type' => $productType,
            'workshop' => $workShop,
            'storage_uuid' => $storageUuid,
            'supplier_uuid' => $supplierUuid,
            'remark' => $remark,
            'status' => AppConstant::NEW_BOM,
            'type' => $type,
            'operate_type' => $operateType,
            'hidden' => $hidden,
            'time' => get_current_time()
        ];
    }

    public static function bomDetailTemplate($bomUuid, $materielId, $count)
    {
        return [
            'uuid' => create_uuid(),
            'bom_uuid' => $bomUuid,
            'sub_materiel_id' => $materielId,
            'count' => $count,
            'flag' => 0
        ];
    }

    public static function returnReelsTemplate($reelId, $seatCode, $materielId, $count)
    {
        return [
            'reelId' => $reelId,
            'seatCode' => $seatCode,
            'materielId' => $materielId,
            'count' => $count
        ];
    }

    public static function purchaseTemplate($purchaseId, $storageUuid, $remark)
    {
        return [
            'uuid' => create_uuid(),
            'purchase_id' => $purchaseId,
            'storage_uuid' => $storageUuid,
            'time' => get_current_time(),
            'remark' => $remark
        ];
    }

    public static function purchaseDetailTemplate($reelId, $subMaterielId, $count, $purchaseId,$supplierId)
    {
        return [
            'uuid' => create_uuid(),
            'purchase_id' => $purchaseId,
            'reel_id' => $reelId,
            'sub_materiel_id' => $subMaterielId,
            'count' => $count,
            'time' => get_current_time(),
            'supplier_id' => $supplierId
        ];
    }
}